import {
    UserProfilesAPI
} from '@/requset/api'

export default {
    namespaced: true,
    // 数据
    state: {
       //购物车数量
        cartTotal: 100,
        // 用户信息
        userInfo: {
            nickName: '昵称',
            coin: 1000,
            headImg:require('../../assets/img/service.848ec511.png')
        }
    },
    mutations: {
        updateUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal;
            state.userInfo = payload.userInfo
        },
        initUserInfo(state) {
            state.cartTotal = 0;
            state.userInfo = {
                headImg: require('../../assets/img/userImg.f8bbec5e.png'),
                nickName: '--',
                coin:'--'
            }
        }
    },
    actions: {
        //获取用户信息(异步)+更新vuex中用户数据触发(mutations)
        async asyncChangeUserInfo({
            commit
        }, payload) {
            let res = await UserProfilesAPI()
            // console.log('用户信息为', res.data);
            commit('updateUserInfo',res.data)
        }
    }
}